package com.tanhua.dubbo.mongo.api;

import com.tanhua.model.mongo.UserLevel;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;

@DubboService
public class UserLevelApiImpl implements UserLevelApi {

    @Autowired
    private MongoTemplate mongoTemplate;

    @Override
    public UserLevel findByUserId(Long userId) {

        Query query = Query.query(Criteria.where("userId").is(userId));

        UserLevel userLevel = mongoTemplate.findOne(query, UserLevel.class);
        return userLevel;
    }
}
